<?php
/*
 * @Author: your name
 * @Date: 2020-05-22 09:43:54
 * @LastEditTime: 2020-05-25 15:09:03
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /v3/application/adminapiv3/controller/attackLogManage/networkLogManage/NetworkAttackController.php
 */ 
namespace app\adminapiv3\controller\attackLogManage\networkLogManage;

use app\adminapiv3\controller\Base;
use app\adminapiv3\service\attackLogManage\AttackLogService;
use app\adminapiv3\service\attackLogManage\networkLogManage\NetworkLogService;
use app\adminapiv3\service\hostRuleManage\HostRuleService;
use app\common\service\HostRule;
use app\common\service\NetworkAttack;

class NetworkAttackController extends Base
{
    /**
     * @name: 列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-05-22 09:45:38
     */
    function list ()
    {
        $input['description'] = $this->filterInput('description', 'get');
        $input['src_ip'] = $this->filterInput('attack_src', 'get');
        $input['dest_ip'] = $this->filterInput('attack_dest', 'get');
        $input['domain_name'] = $this->filterInput('domain_name', 'get');
        $input['url'] = $this->filterInput('url', 'get');
        $input['atime'] = $this->filterInput('atime', 'get');
        $input['type'] = $this->filterInput('type', 'get');
        $input['level'] = $this->filterInput('level', 'get');
        $input['handle'] = $this->filterInput('handle', 'get');
        $input['limit'] = $this->filterInput('limit', 'get', 10);

        $NetworkLogService = new NetworkLogService();
        $data = $NetworkLogService->list($input);

        $this->jsonOutPut($data);
    }

    /**
     * @name: 数据包
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-05-22 09:59:47
     */
    function dataPackage ()
    {
        $host_id = $this->filterInput('host_id*', 'post');//host_id
        $event_id = $this->filterInput('event_id*', 'post');//event_id类型
        $atime = $this->filterInput('atime*', 'post');//atime类型

        $AttackLogService = new AttackLogService();
        $data = $AttackLogService->dataPackage($host_id, $event_id, $atime);

        $this->jsonOutPut($data);

    }

    /**
     * @name: 批量删除
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-05-22 10:54:26
     */
    function bulkDelete ()
    {
        global $logContent;
        $logContent = '批量删除网络日志';

        $id_s = $this->filterInput('id*', 'post');//删除id

        $NetworkLogService = new NetworkLogService();
        $NetworkLogService->delete($id_s);

        $this->jsonOutPut();
    }

    /**
     * @name: 清空所有
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-05-22 10:54:45
     */
    function clear ()
    {
        global $logContent;
        $logContent = '清空网络日志';

        $NetworkLogService = new NetworkLogService();
        $NetworkLogService->clear();

        $this->jsonOutPut();
    }

    /**
     * @name: 启用对应规则
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-05-22 14:21:44
     */
    function enableRule ()
    {
        global $logContent;
        $logContent = '启用网络日志规则';


        $ruleId = $this->filterInput('rule_id*', 'post');
        $host_id = $this->filterInput('host_id*', 'post');

        $baseServer = new \app\adminapiv3\service\Base();
        $baseServer->checkOptionHost($host_id);

        $HostRuleService = new HostRuleService();
        $HostRuleService->enableRule($ruleId, $host_id);


        $this->jsonOutPut([], true);

        $this->Async('Wipf', 'WipfRules');
    }

    /**
     * @name: 停用对应规则
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-05-22 14:21:44
     */
    function disableRule ()
    {
        global $logContent;
        $logContent = '停用网络日志规则';

        $ruleId = $this->filterInput('rule_id*', 'post');
        $host_id = $this->filterInput('host_id*', 'post');

        $baseServer = new \app\adminapiv3\service\Base();
        $baseServer->checkOptionHost($host_id);

        $HostRuleService = new HostRuleService();
        $HostRuleService->disableRule($ruleId, $host_id);

        $this->jsonOutPut([], true);

        $this->Async('Wipf', 'WipfRules');
    }

    /**
     * @name: 添加ip 到白名单
     * @Param:
     * @Description:
     * @Author: foo
     * @Date: 2020-05-25 14:55:11
     */
    function addIpToWhiteList ()
    {
        global $logContent;
        $logContent = '网络日志加入IP白名单';

        $ip = $this->filterInput('ip*', 'post');
        $attack_id = $this->filterInput('attack_id*', 'post');//id
        $host_id = $this->filterInput('host_id*', 'post');

        $baseServer = new \app\adminapiv3\service\Base();
        $baseServer->checkOptionHost($host_id);

        $HostRuleService = new HostRuleService();
        $data['rule_id'] = $HostRuleService->addIpToWhiteList($host_id, $ip, $attack_id);

        $this->jsonOutPut($data);

        $this->Async('Wipf', 'WipfRules');
    }

    /**
     * @name: 清空ip 白名单
     * @Param:
     * @Description:
     * @Author: foo
     * @Date: 2020-05-25 14:55:11
     */
    function clearIpToWhiteList ()
    {
        global $logContent;
        $logContent = '网络日志移除IP白名单';

        $ip = $this->filterInput('ip*', 'post');
        $attack_id = $this->filterInput('attack_id*', 'post');
        $host_id = $this->filterInput('host_id*', 'post');

        $baseServer = new \app\adminapiv3\service\Base();
        $baseServer->checkOptionHost($host_id);

        $HostRuleService = new HostRuleService();
        $HostRuleService->clearIpToWhiteList($host_id, $ip, $attack_id);

        $this->jsonOutPut([], true);

        $this->Async('Wipf', 'WipfRules');
    }

    /**
     * @name告警
     * @author wx
     * @date 2020/6/5 18:07
     */
    function warnning()
    {
        $server = new NetworkAttack();
        $list = $server->warning();

        $this->jsonOutPut($list);
    }
}

